//
//  MYGFindAPI.swift
//  MYGrow
//
//  Created by 小火科技 on 2024/3/18.
//

import UIKit
import Moya

enum MYGFindAPI: MYGTargetType {
    case list(type: Int = 1, list_type: Int, page: Int = 1, pageSize: Int = 20, keywords: String? = nil)
    case add(content: String, type: Int, medias: [String] = [], address: String, lng: String, lat: String, range: Int)
    case detail(id: Int, page: Int)
    case comment(post_id: Int, content: String, parent_id: Int? = nil)
    /// type: 7动态 9评论
    case like(type: Int, status: Int, id: Int)
}

extension MYGFindAPI {
    var path: String {
        switch self {
        case .list:
            "/api/micro/posts"
        case .add:
            "/api/micro/posts"
        case .detail(let id, _):
            "/api/micro/posts/\(id)"
        case .comment:
            "/api/micro/posts/comment"
        case .like:
            "/api/micro/posts/like"
        }
    }
    
    var params: [String : Any] {
        var params: [String: Any] = [:]
        switch self {
        case .list(let type, let list_type, let page, let pageSize, let keywords):
            params["type"] = type
            params["list_type"] = list_type
            params["page"] = page
            params["pageSize"] = pageSize
            params["is_top"] = 0
            if let keywords = keywords {
                params["kwd"] = keywords
            }
        case let .add(content, type, medias, address, lng, lat, range):
            params["content"] = content
            params["type"] = type
            params["medias"] = medias
            params["address"] = address
            params["lng"] = lng
            params["lat"] = lat
            params["range"] = range
        case let .detail(_, page):
            params["page"] = page
            params["pageSize"] = 100
        case let .comment(post_id, content, parent_id):
            params["post_id"] = post_id
            params["content"] = content
            params["parent_id"] = parent_id
        
        case .like(type: let type, status: let status, id: let id):
            params["like_type"] = type
            params["like_status"] = status
            params["id"] = id
        }
        return params
    }
    
    var baseURL: URL {
        switch self {
        case .list, .add , .detail,.comment,.like:
            return  URL(string: BaseUrl)!
        }
    }
    
    var method: Moya.Method {
        switch self {
        case .list:
            .get
        case .add:
            .post
        case .detail:
            .get
        case .comment:
            .post
        case .like:
            .post
        }
    }

}
